home *** CD-ROM | disk | FTP | other *** search
/ Language/OS - Multiplatform Resource Library / LANGUAGE OS.iso / et / et-2_2.lha / et2.2 / src / System.h < prev    next >
C/C++ Source or Header  |  1990-11-28  |  4KB  |  156 lines

  1. #ifndef System_First
  2. #ifdef __GNUG__
  3. #pragma once
  4. #endif
  5. #define System_First
  6.  
  7. #include "Object.h"
  8.  
  9. //---- class SysEvtHandler ---------------------------------------
  10. // abstract class for handling events from system resources
  11.  
  12. enum SysEventCodes {
  13.     eSysEvtRead,
  14.     eSysEvtWrite,
  15.     eSysEvtZombie,
  16.     eSysEvtSignal,
  17.     eSysEvtAsyncSignal,
  18.     eSysEvtTimeout
  19. };
  20.  
  21. class SysEvtHandler : public Object {
  22. friend class System;
  23.     class Collection *owner;
  24.     int resourceId;
  25.     void SetOwner(Collection *o)
  26.     { owner= o; }
  27. protected:
  28.     ~SysEvtHandler();
  29. public:
  30.     MetaDef(SysEvtHandler);
  31.     SysEvtHandler(int resource);
  32.     int GetResourceId();
  33.     void SetResourceId(int);
  34.     virtual void Notify(SysEventCodes code, int val);
  35.     virtual bool HasInterest();
  36.     virtual bool ShouldRemove();
  37.     void Remove();
  38.     bool IsEqual(Object *op);
  39. };
  40.  
  41. //---- Signals -----------------------------------------------------------------
  42.  
  43. enum Signals {
  44.     eSigBus,
  45.     eSigSegmentationViolation,
  46.     eSigSystem,
  47.     eSigPipe,
  48.     eSigIllegalInstruction,
  49.     eSigQuit,
  50.     eSigInterrupt,
  51.     eSigWindowChanged,
  52.     eSigAlarm,    
  53.     eSigChild,
  54.     eSigUrgent
  55. };
  56.  
  57. //---- System ------------------------------------------------------------------
  58.  
  59. typedef void (*CallFunc)(void*, void*, void*, void*);
  60.  
  61.  
  62. class System : public Root {
  63. protected:
  64.     bool done;
  65.     char *errorstr, *osid;
  66.  
  67.     Collection *fileInputHandler;
  68.     Collection *fileOutputHandler;
  69.     Collection *zombieHandler;    
  70.     Collection *signalHandler;    
  71.     Collection *asyncSignalHandler;    
  72.     Collection *timeoutHandler;
  73.     Collection *cleanupList;
  74.  
  75. public:  
  76.     static bool anyremoved;
  77.  
  78. public:
  79.     System(char *name= "GENERIC");
  80.     virtual ~System();
  81.  
  82.     virtual bool Init();
  83.  
  84.     char *GetErrorStr()
  85.     { return errorstr; }
  86.     virtual char *GetError();
  87.     char *GetSystemId()
  88.     { return osid; }
  89.     virtual void Control();
  90.     void ExitControl()
  91.     { done= TRUE; }
  92.     virtual void InnerLoop();
  93.     virtual bool CanRead(int fd, int timeout);
  94.  
  95.     virtual class Directory *MakeDirectory(char *name);
  96.     virtual class FileType *GetFileType(char *path, bool shallow= FALSE);
  97.     virtual void  Rename(char *from, char *to);
  98.     
  99.     //---- expand the metacharacters in Pat as in the shell
  100.     virtual bool ExpandPathName(char *patbuf, int buflen);    
  101.     virtual bool AccessPathName(char *path, int mode= 0);
  102.     virtual bool ChangeDirectory(char *path);
  103.     virtual char *WorkingDirectory();
  104.     virtual char *HomeDirectory();
  105.     
  106.     virtual void exit(int code, bool mode= TRUE);
  107.     virtual void GetTtyChars(char &backspace, char &rubout);
  108.     virtual void wait(unsigned int);
  109.     virtual void abort(int code= 0);
  110.  
  111.     //---- pseudo tty connection --------------------------------
  112.     virtual class PttyConnection *MakePttyConnection(char *prog, char **args);
  113.  
  114.     //---- environment manipulation -----------------------------
  115.     virtual void Setenv(char *name, char *value);
  116.     // set environment variable name to value   
  117.     virtual void Unsetenv(char *name);
  118.     // remove environment variable
  119.     virtual char *getenv(char *);
  120.  
  121.     //---- Dynamic Loading --------------------------------------
  122.     virtual int Call(CallFunc cf, void *p1, void *p2, void *p3, void *p4);
  123.     virtual Object *Load(char *progname, char *name);
  124.  
  125.     //---- handling of system events ----------------------------
  126.     SysEvtHandler *AddFileInputHandler(SysEvtHandler *);
  127.     SysEvtHandler *AddFileOutputHandler(SysEvtHandler *);
  128.     SysEvtHandler *AddZombieHandler(SysEvtHandler *);
  129.     SysEvtHandler *AddSignalHandler(SysEvtHandler*, bool sync= TRUE);
  130.     SysEvtHandler *AddTimeoutHandler(SysEvtHandler *);
  131.     SysEvtHandler *RemoveTimeoutHandler(SysEvtHandler *);
  132.     void AddCleanupObject(Object*);
  133.     void Remove();
  134. };
  135.  
  136. extern System   *gSystem;
  137. extern char     gBackspace;
  138. extern char     gRubout;
  139. extern char     *gEtDir;
  140.  
  141. inline void Wait(unsigned int duration)
  142.     { gSystem->wait(duration); }
  143.  
  144. inline void Exit(int code, bool mode= TRUE)
  145.     { gSystem->exit(code, mode); }
  146.  
  147. inline void Abort()
  148.     { gSystem->abort(); }
  149.  
  150. inline char *Getenv(char *name)
  151.     { return gSystem->getenv(name); }
  152.  
  153. extern "C" void _exit(int code);
  154.  
  155. #endif System_First
  156.